# 需求：密码长度不足6位，则报异常

# 1、自定义异常类，继承Exception
class ShortInputError(Exception):
    def __init__(self, length, min_len):
        self.length = length
        self.min_len = min_len

    # 设置抛出异常的描述信息
    def __str__(self):
        return f'你输入的密码长度是{self.length}，不能少于{self.min_len}个字符'


# 2、抛出异常 -- raise方法
def main():
    try:
        password = input('请输入密码：\n')
        if len(password) < 6:
            raise ShortInputError(len(password), 6)

    # 3、捕获该异常
    except Exception as e:
        print(e)

    else:
        print('该密码可用')

main()
